home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11070 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: passing struct to constructor  -  temp.txt [1/1]
  5. Date: Tue, 12 Mar 1996 15:47:20 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4i468t$pa7@news.halcyon.com>
  8. References: <4eqgq3$5g1@geraldo.cc.utexas.edu> <4hseh1$rkk@news2.delphi.com>
  9. NNTP-Posting-Host: blv-pm3-ip12.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. JGUILLORY@delphi.com wrote:
  13.  
  14.  
  15. >Quoting wharris from a message in comp.lang.c++
  16. > wh>The compiler error I'm getting is "VIN is not a member of struct1".  The
  17. > wh>code has been severely minimized, however this should have the bare
  18. > wh>essentials required to solve the problem.
  19. > wh>class CarData
  20. > wh>{
  21. > wh>private :
  22. > wh>char VIN[7];
  23. > wh>public :
  24. > wh>CarData(struct astruct1 CarInf);
  25. > wh>};
  26. > wh>//********************************************************
  27. > wh>CarData::CarData(struct astruct1 CarInf)
  28. > wh>{
  29. > wh>strcpy(VIN,CarInf.VIN);
  30. > wh>}
  31. > wh>struct astruct1
  32. > wh>    {
  33. > wh>    char VIN[7];
  34. > wh>    }CarInfo;
  35. > wh>void main()
  36. > wh>{
  37. > wh>CarData CarConst1(struct astruct1 CarInfo);
  38. > wh>}
  39.  
  40. >  The key is 'private:'   Using private restricts access to VIN
  41. >  by any other part of your program except from within the object
  42. >  (CarData)..
  43.  
  44. Eh?  The problem is CarData::CarData uses astruct1 before it's been
  45. defined so the compiler doesn't know VIN is a part of it.   
  46.  
  47. Moreover, main() tries to instantiate CarConst1 by passing it a
  48. type-declaration instead of an actual instance of astruct1.
  49.  
  50.